%--------------------------------------------------------------------------
%
% computes the leading order (in delta) solution to the basic state and
% then compares to the numerical one
%
%--------------------------------------------------------------------------

function base_compare(p)


if nargin == 0
    p = params;
end
s = base(p);

max_v = abs(s.y(end-1,:));
h = s.y(end,:);
t = s.x;

h_comp = -(1 + lambertw(-p.beta / (p.beta - 1) * exp(((-p.beta + p.delta * t) / (p.beta - 1))))) * (p.beta - 1);


semilogx(t, h, 'k', t, h_comp, 'r--', 'linewidth',1);
xlim([0, max(t) / 2]);
xlabel('$t$', 'interpreter','latex','fontsize',12);
ylabel('$h(t)$', 'interpreter','latex','fontsize',12);
l = legend('numerical','matched asymptotic', 'location','best');
set(l, 'interpreter','latex','fontsize',11);

v_asy = (1 - p.beta) * (1 - 1 ./ h);


v1 = sep_var(0);

figure;
loglog(t, max_v, 'k', t, abs(v_asy), 'r--',t, abs(v1(end,:)), 'b-.', 'linewidth',1);
ylim([1e-5, 1]);
xlabel('$t$', 'interpreter','latex','fontsize',12);
ylabel('$|v(h(t),t)|$', 'interpreter','latex','fontsize',12);
l = legend('numerical','$t = O(\delta^{-1})$ asymptotic', '$t = O(1)$ asymptotic', ...
    'location', 'best');
set(l, 'interpreter','latex','fontsize',11);
